package org.springblade.modules.repair.controller;

import org.springblade.common.cache.DictCache;
import org.springblade.core.secure.utils.AuthUtil;
import org.springblade.core.tool.api.R;
import org.springblade.modules.repair.vo.DeptAddressListVO;
import org.springblade.modules.repair.service.IMaintainPlanContentService;
import org.springblade.modules.repair.service.IUserSignDetailService;
import org.springblade.modules.repair.vo.*;
import org.springblade.modules.system.entity.Dict;
import org.springblade.modules.system.service.IDeptService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Date 13:58 2021/5/24
 * @Description {
 *	维保小程序首页接口
 * }
 * @Author lsay
 **/
@RestController
@RequestMapping("/repair/home")
public class RepairHomeController {

	@Autowired
	private IMaintainPlanContentService planContentService;
	@Autowired
	private IUserSignDetailService userSignDetailService;
	@Autowired
	private IDeptService deptService;

	/**
	 * 获取用户部分字典数据
	 * @param key
	 * @return
	 */
	@GetMapping("/user/dict")
	public R<List<Dict>> selectUserDict(String key){
		return R.data(DictCache.getList(key));
	}

	/**
	 * 获取首页用户今日任务状态统计
	 * @return
	 */
	@GetMapping("/user/plan/status")
	public R<HomePlanStatusCountVO> selectUserPlanStatus(){
		return R.data(planContentService.selectUserPlanStatus(AuthUtil.getUserId()));
	}

	/**
	 * 获取首页用户我的申请统计
	 * @return
	 */
	@GetMapping("/user/plan/approve")
	public R<HomePlanApproveCountVO> selectUserPlanApprove(){
		return R.data(planContentService.selectUserPlanApprove(AuthUtil.getUserId()));
	}

	/**
	 * 获取首页用户我的审批统计
	 * @return
	 */
	@GetMapping("/user/plan/apply")
	public R<HomePlanApplyCountVO> selectUserPlanApply(){
		return R.data(planContentService.selectUserPlanApply(AuthUtil.getUserId()));
	}

	/**
	 * 获取首页用户今日考勤状态及本月考勤统计
	 * @return
	 */
	@GetMapping("/user/sign")
	public R<HomeUserSignCountVO> selectUserSign(){
		return R.data(userSignDetailService.selectUserSign(AuthUtil.getUserId()));
	}

	/**
	 * 获取首页用户部门负责项目电梯及任务
	 * @return
	 */
	@GetMapping("/dept/building/plan")
	public R<HomeDeptBuildingPlanCountVO> selectDeptBuildingPlanCount(){
		return R.data(planContentService.selectDeptBuildingPlanCount(AuthUtil.getUserId()));
	}

	/**
	 * 获取首页用户部门负责项目电梯及任务
	 * @return
	 */
	@GetMapping("/user/building/plan")
	public R<HomeDeptBuildingPlanCountVO> selectUserBuildingPlanCount(){
		return R.data(planContentService.selectUserBuildingPlanCount(AuthUtil.getUserId()));
	}

	/**
	 * 获取部门人员通讯录
	 * @return
	 */
	@GetMapping("/dept/address/list")
	public R<List<DeptAddressListVO>> listDeptAddressList(Long deptId){
		return R.data(deptService.selectDeptAddressList(deptId));
	}

	/**
	 * 获取部门人员通讯录
	 * @return
	 */
	@GetMapping("/user/address/list")
	public R<List<DeptAddressListUserVO>> listUserAddressList(Long deptId){
		return R.data(deptService.listUserAddressList(deptId));
	}

}

































